package com.shengyin.ec.model.dao.goods;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.shengyin.ec.model.dao.BaseDaoImpl;
import com.shengyin.ec.model.entity.GoodsType;

@Repository("goodsTypeDao")
public class GoodsTypeDaoImpl extends BaseDaoImpl<GoodsType> implements GoodsTypeDao {

	public List<GoodsType> getGoodsTypeList(int offset,int pagesize){
		
		return super.findByPage("From GoodsType gType",offset, pagesize);
	}

	@Override
	public List<GoodsType> getGoodsTypeByParentName(String parentName) {
		return super.find("From GoodsType gt where parentTypeName='"+parentName+"'");
	}

	@Override
	public List<GoodsType> getGoodsTypeByChild(int childNum) {
		return super.find("From GoodsType gt where gt.childNum="+childNum);
	}
	
	@Override
	public List<GoodsType> getGoodsTypeByParentID(int parentId) {
		return super.find("From GoodsType gt where gt.parentId="+parentId);
	}
	
	public Long getTotal(){
		return (Long) super.find("select count(*) from GoodsType").get(0);
	}

	@Override
	public boolean goodsTypeCheck(String typeName) {
		List<GoodsType> goodsTypeList=super.find("From GoodsType gt where gt.typeName="+typeName);
		if(goodsTypeList.size()!=0){
			return true;
			}
		return false;
	}
	
	public List<GoodsType> getGoodsTypeList(){
		return super.loadAll();
	}

	@Override
	public long getGoodsTypeCount(String goodsTypeName) {
		return (Long) super.find("select count(*) from Goods gt where gt.productType='"+goodsTypeName+"'").get(0);
	}

    public List<GoodsType> getGoodsTypeByKeyword(String keyword,int offset,int pageSize){
    	return super.findByPage("from GoodsType where typeName like ?", '%'+keyword+'%', offset, pageSize);
    }
	
	public List<GoodsType> getGoodsTypeByKeyword(String keyword){
		String sql = "from GoodsType where typeName like '%"+keyword+"%'";
		System.out.println("sql====" + sql);
		return super.find("from GoodsType where typeName like '%"+keyword+"%'");
	}
}
